﻿namespace SchoolSystem.Server.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Runtime.Serialization;
    using SchoolSystem.Data;

    [DataContract(Name = "student")]
    public class StudentFullModel : StudentModel
    {
        [DataMember(Name = "class")]
        public ClassModel Class { get; set; }

        [DataMember(Name = "disciplines")]
        public IEnumerable<DisciplineForStudentModel> Disciplines { get; set; }

        public static Expression<Func<Student, StudentFullModel>> FromStudent
        {
            get
            {
                return s => new StudentFullModel()
                {
                    FirstName = s.FirstName,
                    MiddleName = s.MiddleName,
                    LastName = s.LastName,

                    Class = new ClassModel()
                    {
                        Year = s.Class.Year,
                        SpecialIdentifier = s.Class.SpecialIdentifier,
                    },

                    Disciplines = s.Class.Disciplines.AsQueryable().Select(DisciplineForStudentModel.FromDiscipline)
                };
            }
        }
    }
}